package com.qvtu.poetry.common.config;


import com.qvtu.poetry.common.Interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author:
 * @Description: web拦截器
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {

    //拦截对象
    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 添加拦截器
     *
     * @param registry
     */
    @Override
    public void addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry) {
        //拦截路径
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**") // 拦截所有请求
                .excludePathPatterns(
                        "/ai/**",
                        "/user/login",
                        "/user/register",
                        "/captcha/**",
                        "/poem/search",         // POST 搜索
                        "/poem/search/**",     // 覆盖尾斜杠等变体
                        "/poem/detail/**",     // 诗歌详情 GET 公共接口
                        "/poem/list",          // 诗歌列表 GET 公共接口
                        "/poem/create",        // 生成诗歌 POST 公共接口
                        "/api/poem/search",    // 若前端网关带有 /api 前缀
                        "/api/poem/search/**",
                        "/common/upload",
                        "/music/details/rand"
                ); // 放行公共接口
    }
}
